
class_name CardData

var card: Card

# 额外数据
var data = {}

## 显示数据
var cardName: String
var cardDesc: String
var image: Texture

var isDead: bool = false

## 战斗基础数据
var hp: int
var maxHp: int
var attack: int
var defence: int
var speed: int

## 是否是怪物
var isMonster: bool = false
var lastAttackTime: int

## 战斗的函数
var onAttack = func(targets: Array):
	
	if targets.is_empty():
		return
	
	var target: Card = targets.pick_random()
	
	var damage = attack
	var result_damage = target.data.onDefence.call(damage)
	
	var endCall = func ():
		target.data.onHurt.call(result_damage)
		target.runHurtAnim(result_damage)
	
	card.runAttackAnim(target, endCall)
	
	lastAttackTime = Time.get_ticks_msec()
	

var onCure = func(damage: int):
	hp += damage
	
	if hp > maxHp:
		hp = maxHp
		

var onDefence = func(damage: int):
	
	if damage < defence:
		return 1;
	
	return damage - defence
	
var onHurt = func(damage):
	hp -= damage
	if hp <= 0:
		hp = 0
		
		onDead.call()


var onDead = func():
	isDead = true
	card.runDeadAnim()


var getSpeed = func():
	return speed
	
	
var upLine = func():
	pass
	

var canAttack = func() -> bool:
	var delay = Time.get_ticks_msec() - lastAttackTime
	var speed = getSpeed.call()
	var cdtime: float = (10.0 / speed) * 1000
	return delay >= cdtime
